<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
</head>
<body>
<!--    新增-->
    <input type="button" value="POST请求" onclick="clickPost()"><br/>
<!--    查询-->
    <input type="button" value="GET请求" onclick="clickGET()"><br/>
<!--   删除-->
    <input type="button" value="Delete请求" onclick="clickDelete()"><br/>
<!--    修改-->
    <input type="button" value="PUT请求" onclick="clickPut()"><br/>

    <script type="text/javascript">
        function clickGET(){
            $.ajax({
                type:"GET",
                url:"/users/",
                contentType:"application/json",
                xhrFields:{
                    //    跨域访问携带cookie
                    withCredentials:true
                },
                success:function (data){
                    console.log(data);
                    alert("SUCCESS");
                },
                error:function (data){
                    console.log(data);
                    alert("fail");
                }
            })
        }
        function clickPost(){
            var param={"id":1,"username":"tom","password":"123456","nickname":"admin"};
            $.ajax({
                type:"post",
                data:JSON.stringify(param),
                url:"/users/",
                contentType: "application/json",
                xhrFields:{
                //    跨域访问携带cookie
                    withCredentials:true
                },
                success:function (data) {
                    alert(data);
                },
                error:function (data) {
                    console.log(data);
                }
            })
        }
        function clickDelete(){
            $.ajax({
                type:"delete",
                url:"/users/1",
                contentType:"application/json",
                xhrFields:{
                    //    跨域访问携带cookie
                    withCredentials:true
                },
                success:function (data) {
                    alert(data);
                },
                error:function (data) {
                    console.log(data);
                }
            })
        }
        function clickPut(){
            var param={"id":1,"username":"tom","password":"123456","nickname":"admin"};
            $.ajax({
                type:"put",
                data:JSON.stringify(param),
                url:"/users/",
                contentType:"application/json",
                xhrFields:{
                    //    跨域访问携带cookie
                    withCredentials:true
                },
                success:function (data) {
                    alert(data);
                },
                error:function (data) {
                    console.log(data);
                }
            })
        }
    </script>
</body>
</html>